package com.lfl.util;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @program: JavaEE-EFD
 * @description: 配置文件读取类, properties配置文件读取,property配置文件读取
 * @author: fengjd
 * @create: 2022-07-27 17:41
 **/
public class PropertyUtil {

    static Properties properties;

    static InputStream in;

    private PropertyUtil(Properties properties) {
        this.properties = properties;
    }

    public static Properties getInstance() {
        if (properties == null) {
            try {
                in = new FileInputStream(PropertyUtil.class.getResource(".").getPath() + "druid.properties");
                Properties prop = new Properties();
                prop.load(in);
                properties = prop;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return properties;
    }

    public static void close() {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
